<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>竣工验收监督</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Expires" CONTENT="0">
    <meta http-equiv="Cache-Control" content="no-siteapp,no-transform,no-store, no-cache, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="/static/css/buildUnit/common.css">
    <style>
        body {
            height: auto;
        }

        .content {
            padding: 20px;
        }
        .layui-container {
            padding-top: 20px;
            width: auto;;
        }

        /*单元格备注样式*/
        .layui-table td.tdBz {
            text-align: left;
            padding-left: 0;
            border-left: none;
            color: #aaa;
        }

        .padNone .layui-form-select .layui-input {
            padding-right: 0;
        }

        .hide {
            display: none;
        }
    </style>
</head>
<body>
<div class="layui-container">
    <form id="form" class="layui-form layui-form-pane" action="" lay-filter="example">
        <input type="hidden" name="id" class="formData" value="">
        <input type="hidden" name="cptId" class="formData" value="">
        <input type="hidden" name="createTime" class="formData" value="">

        <div class="layui-collapse">
            <div class="layui-colla-item">
                <h2 class="layui-colla-title">工程竣工验收监督记录（一）</h2>
                <div class="layui-colla-content layui-show">
                    <table class="layui-table v-table">
                        <tbody>
                            <tr class="hide">
                                <td width="24%"></td>
                                <td width="13%"></td>
                                <td width="13%"></td>
                                <td width="24%"></td>
                                <td width="13%"></td>
                                <td width="13%"></td>
                            </tr>
                            <tr>
                                <td class="th8 required">项目名称</td>
                                <td colspan="2">
                                    <input id="prjName" name="prjName" class="layui-input formData" autocomplete="off" readonly/>
                                </td>
                                <td class="th8 required">项目编号</td>
                                <td colspan="2">
                                    <input name="prjCode" class="layui-input formData" autocomplete="off" readonly>
                                </td>
                            </tr>
                            <tr>
                                <td class="th8 required">单位工程名称</td>
                                <td colspan="2">
                                    <input id="unitPrjName" name="unitPrjName" class="layui-input formData" autocomplete="off" readonly/>
                                </td>
                                <td class="th8 required">监督时间</td>
                                <td colspan="2">
                                    <input name="supDate" id="supDate" placeholder="监督时间" autocomplete="off" class="layui-input formData" lay-verify="required" readonly>
                                </td>
                            </tr>
                            <tr>
                                <td class="th8 required">质量控制资料及结构安全和主要使用功能抽查报告</td>
                                <td colspan="5">
                                    <input name="spotCheck" lay-verify="isEmpty" class="layui-input formData" placeholder="抽查报告" autocomplete="off">
                                </td>
                            </tr>
                            <tr>
                                <td class="th8 required">观感质量验收</td>
                                <td colspan="5">
                                    <input name="accQuality" lay-verify="isEmpty" class="layui-input formData" placeholder="观感质量验收" autocomplete="off">
                                </td>
                            </tr>
                            <tr>
                                <td class="th8 required">综合验收结论</td>
                                <td colspan="5">
                                    <input name="accConclusion" lay-verify="isEmpty" class="layui-input formData" placeholder="综合验收结论" autocomplete="off">
                                </td>
                            </tr>
                            <tr>
                                <td class="th8 required">专家评价意见</td>
                                <td colspan="5">
                                    <input name="expertOpinion" lay-verify="isEmpty" class="layui-input formData" placeholder="专家评价意见" autocomplete="off">
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <input type="button" id="sign1" value="各单位责任人签名" class="layui-btn" style="display:none" lay-filter="sign1">
                    <input type="button" id="sign11" value="重新签名" class="layui-btn" style="display:none" lay-filter="sign11">
                    <input type="button" id="download1" value="下载附件" style="display:none" lay-filter="download1" class="layui-btn layui-btn-xs">
                </div>
            </div>
            <script type="text/html" id="toolbarOrg1">
                <div class="layui-btn-container">
                    <input type="button"class="layui-btn" lay-event="add" value="上传文件">
                </div>
            </script>

            <script type="text/html" id="toolbarOrg11">
                <div class="layui-btn-container">
                    <!--不能修改-->
                </div>
            </script>
            <script type="text/html" id="barDemo1">
                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="delete1">删除</a>
                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="download1">下载</a>
            </script>
            <script type="text/html" id="barDemo11">
                <!--不能修改-->
            </script>
        </div>

        <div class="layui-collapse">
            <div class="layui-colla-item">
                <h2 class="layui-colla-title">永久性质量责任标牌照片</h2>
                <div class="layui-colla-content layui-show">
                    <table class="layui-hide" id="dataList2" lay-filter="dataList2"></table>
                </div>
            </div>
        </div>

        <div class="layui-collapse">
            <div class="layui-colla-item">
                <h2 class="layui-colla-title">工程竣工验收监督记录（二）</h2>
                <div class="layui-colla-content layui-show">
                    <table class="layui-table v-table">
                        <tbody>
                        <tr class="hide">
                            <td width="24%"></td>
                            <td width="13%"></td>
                            <td width="13%"></td>
                            <td width="24%"></td>
                            <td width="13%"></td>
                            <td width="13%"></td>
                        </tr>
                        <tr>
                            <td class="th8 required">验收程序</td>
                            <td >
                                <input name="accProcedure" lay-verify="isEmpty"  class="layui-input formData" placeholder="验收程序" autocomplete="off">
                            </td>
                        </tr>
                        <tr>
                            <td class="th8 required">验收组织形式</td>
                            <td ><input name="accModality" lay-verify="isEmpty" class="layui-input formData" placeholder="验收组织形式" autocomplete="off">
                            </td>
                        </tr>
                        <tr>
                            <td class="th8 required">执行验收标准情况</td>
                            <td><input name="accSituation" lay-verify="isEmpty" class="layui-input formData" placeholder="执行验收标准情况" autocomplete="off">
                            </td>
                        </tr>
                        <tr>
                            <td class="th8 required">监督处理意见</td>
                            <td >
                                <input class="formData" type="radio" name="supSuggest" value="1" title="未见异常"></br>
                                <input class="formData" type="radio" name="supSuggest" value="2" title="责令建设单位组织相关单位处理发现问题并回复"></br>
                                <input class="formData" type="radio" name="supSuggest" value="3" title="责令立即整改，并重新组织竣工验收"></br>
                                <input class="formData" type="radio" name="supSuggest" value="4" title="建议处罚">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <input type="button" id="sign2" value="监督人员签名" class="layui-btn" style="display:none" lay-filter="sign2">
                    <input type="button" id="download2" value="下载附件" style="display:none" lay-filter="download2" class="layui-btn layui-btn-xs">
                </div>
            </div>
        </div>

    </form>
</div>
<script src="/static/js/main.js"></script>
<script type="text/javascript">
    var $;
    layui.use(['jquery', 'element', 'form', 'laydate', 'configure', 'configureCom', 'selectFun', 'bluebird', 'replaceStr', 'jsDictFile', 'mapExtend'], function () {
        $ = layui.jquery;
        var element = layui.element;
        var form = layui.form;
        var configure = layui.configure;
        var table = layui.table;
        var configureCom = layui.configureCom;
        var laydate = layui.laydate;
        var selectFun = layui.selectFun;
        var sessionFun = layui.sessionFun;//存储session
        var listData = sessionFun.get(configure.COMPLETION_ROW_DATA);
        var token = sessionFun.get(configure.SESSION_TOKEN) ? sessionFun.get(configure.SESSION_TOKEN).token : '';
        var cptStatus = sessionFun.get( 'CPT_STATUS');

        var cptAcceptanceId = sessionFun.get('cptAcceptanceId');
        //用于操作附件
        var id = '';
        //申请状态, 用于过滤文件删除按钮
        var status = '';

        //根据申请ID查询条件核查记录
        var res={};

        //日期控件初始化
        laydate.render({
            elem: '#supDate',
            type: 'date'
        });

        //详情或修改页面
        if (listData) {
            form.val('formData', listData);
            //TODO 应该是这里会导致 监督记录的ID等于竣工申请ID
            id = listData.id;
            status = listData.status;
            cptAcceptanceId = listData.id;
        }else if(cptAcceptanceId){
            var res={};
            var data1 = $.extend({cptAcceptanceId:cptAcceptanceId}, {token: token});
            var index = top.layer.load(1, {shade: 0.01});
            $.ajax({
                url: configure.COMPLETION_DETAIL_INFO,
                type: 'get',
                cache: false,
                async:false,
                data: data1,
                dataType: 'json',
                success: function (data) {
                    top.layer.close(index);
                    res = data;
                },
                error: function (data) {
                    top.layer.close(index);
                }
            });
            if(res.data){
                prjId = res.data.prjId;
                prjName = res.data.prjName;
                //TODO 应该是这里会导致 监督记录的ID等于竣工申请ID
                id = res.data.id;
                status = res.data.status;
                form.val('formData', res.data);
            }else{
                //TODO 应该是这里会导致 监督记录的ID等于竣工申请ID
                res.data = { id: cptAcceptanceId};
            }
        //理论上走不到这个逻辑
        }else{
            id = guid();
        };

        /**
         * 永久性质量责任标牌照片
         */
        var table2 = {
            id:'dataList2',
            cols:[[
                {field: 'name', title: '文件名称'},
                {fixed: 'right', title: '操作', toolbar: '#barDemo1', width: 320}
            ]],
            url:configure.SYS_DOC_ATTS_API,
            data:{
                businessId:id,
                code:'CPT_ACCPTANCE_FILES_YJXZLZRBPZP'
            },
            page:false
        }
        if(status && status==2){
            configureCom.tableRenderGet(table2.url, table2.data, table2.cols, table2.id, 10, '', 'toolbarOrg1',table2.page);
        }else{
            table2.cols=[[
                {field: 'name', title: '文件名称'},
                {fixed: 'right', title: '操作', toolbar: '#barDemo11', width: 320}
            ]];
            configureCom.tableRenderGet(table2.url, table2.data, table2.cols, table2.id, 10, '', 'toolbarOrg11',table2.page);
        }
        //头工具栏事件
        table.on('toolbar(dataList2)', function (obj) {
            switch (obj.event) {
                case 'add':
                    sessionFun.set(configure.SESSION_UPLOAD_CONFIG,{
                        url:configure.COMMON_UPLOAD_API,
                        formData:{
                            businessId:id,
                            code:'CPT_ACCPTANCE_FILES_YJXZLZRBPZP'
                        },
                        accept:{
                            title: '文件上传',
                            extensions: 'gif,jpg,jpeg,bmp,png,dwg,doc,docx,xls,xlsx,ppt,pptx,pdf',
                            mimeTypes: 'image/*,application/pdf' +
                            'application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,' +
                            'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,' +
                            'application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,'
                        }
                    });
                    top.layer.open({
                        type: 2,
                        title: '上传附件',
                        content: configure.COMMON_UPLOAD_HTML,
                        area: configureCom.Psize1,
                        cancel: function (index, layero) {
                            configureCom.tableReloadById(table2.id);
                        }
                    });
                    break;
            }
        });
        //每行操作
        table.on('tool(dataList2)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete1') {
                //删除文件
                $.ajax({
                    type: "POST",
                    url: configure.COMMON_FILE_DELETE_API+'?token='+token,
                    data: {
                        "attIds" : data.id
                    },
                    success: function (data) {
                        var code = data.code;
                        var msg = data.msg;
                        if (code == "0" || msg == "success") {

                        } else {
                            layer.msg(data.msg);
                        }
                        layer.closeAll('loading');
                        //页面刷新
                        configureCom.tableReloadById(table2.id);
                    }
                });
            }else if(obj.event === 'download1'){
                window.open(configure.COMMON_FILE_DOWNLOAD_API+'/'+data.id+'?token='+token)
            }
        });


        /**
         * 表单初始化
         */
        //根据申请ID查询条件核查记录
        var res={};
        var data1 = $.extend({cptAcceptanceId:cptAcceptanceId}, {token: token});
        var index = top.layer.load(1, {shade: 0.01});
        $.ajax({
            url: configure.CPT_ACCEPTANCE_SUPERVISE_VIEW_API,
            type: 'get',
            cache: false,
            async:false,
            data: data1,
            dataType: 'json',
            success: function (data) {
                top.layer.close(index);
                res = data;
            },
            error: function (data) {
                top.layer.close(index);
            }
        });

        //如果查到条件核查记录表单赋值,
        if(res.data){
            form.val('example', res.data);
            if(!res.data.id){
                //项目信息有, 核查信息没有
                var newData = { cptId: cptAcceptanceId};
                newData.id = id;
                form.val('example', newData);
            }
        }else{
            //如果没有查到核查记录 则为新增, 表单赋值仅有申请ID
            var newData = { cptId: cptAcceptanceId};
            newData.id = id;
            form.val('example', newData);
        }

        //监听下载1
        $("#download1").click(function(data){
            window.open("/api/cpt/acceptance/supervise/gcjgysjdjl1File/sign/download?token="+token + "&cptId="+cptAcceptanceId);
        });

        //监听下载2
        $("#download2").click(function(data){
            window.open("/api/cpt/acceptance/supervise/gcjgysjdjl2File/sign/download?token="+token + "&cptId="+cptAcceptanceId);
        });

        //监听签名1
        $("#sign1").click(function(data){
            //TODO 后台根据模板生成pdf文件
            var res1 = null;
            var data1 = {id:cptAcceptanceId, reSign:0};
            $.ajax({
                url: '/api/cpt/acceptance/supervise/gcjgysjdjl1File/create?token='+token,
                type: 'post',
                cache: false,
                async:false,
                contentType : 'application/json',
                dataType : 'json',
                data :JSON.stringify(data1),
                success: function (data) {
                    res1 = data;
                    layer.closeAll('loading');
                },
                error: function (data) {
                    layer.closeAll('loading');
                    layer.msg(data.msg?data.msg:"操作失败");
                }
            });

            //查询竣工验收详情, 并判断状态, 是否显示保存按钮
            if(res1 && res1.code==0){
                sessionFun.set(configure.SESSION_SIGN_DATA,{id:cptAcceptanceId, fileName:res1.data.fileName, attId:res1.data.attId});
                //打开插件工具, 盖章上传
                top.layer.open({
                    type: 2,
                    title: '上传附件',
                    content: 'pages/completion/sign/gcjgysjdjl1Sign.html',
                    area: configureCom.Psize1,
                    cancel: function (index, layero) {
//                        configureCom.tableReloadById(table12.id);
                    },
                    btn: ['保存签章'],
                    yes: function (index, layero) {
                        var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        iframeWin.signSave().then(function (res) {
                            if (res.code == 1) {
                                top.layer.msg(res.msg);
                                top.layer.close(index);
                                configureCom.tableReloadById(table12.id);
                            } else {
                                top.layer.alert(res.msg);
                            }
                        });
                    }
                });
            }else if(res1.code){
                layer.msg(res1.msg?res1.msg:"操作失败.");
                return;
            }else{
                layer.msg("操作失败!");
                return;
            }
        });


        //监听重新签名
        $("#sign11").click(function(data){
            //TODO 后台根据模板生成pdf文件
            var res1 = null;
            var data1 = {id:cptAcceptanceId, reSign:1};
            $.ajax({
                url: '/api/cpt/acceptance/supervise/gcjgysjdjl1File/create?token='+token,
                type: 'post',
                cache: false,
                async:false,
                contentType : 'application/json',
                dataType : 'json',
                data :JSON.stringify(data1),
                success: function (data) {
                    res1 = data;
                    layer.closeAll('loading');
                },
                error: function (data) {
                    layer.closeAll('loading');
                    layer.msg(data.msg?data.msg:"操作失败");
                }
            });

            //查询竣工验收详情, 并判断状态, 是否显示保存按钮
            if(res1 && res1.code==0){
                sessionFun.set(configure.SESSION_SIGN_DATA,{id:cptAcceptanceId, fileName:res1.data.fileName, attId:res1.data.attId});
                //打开插件工具, 盖章上传
                top.layer.open({
                    type: 2,
                    title: '上传附件',
                    content: 'pages/completion/sign/gcjgysjdjl1Sign.html',
                    area: configureCom.Psize1,
                    cancel: function (index, layero) {
//                        configureCom.tableReloadById(table12.id);
                    },
                    btn: ['保存签章'],
                    yes: function (index, layero) {
                        var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        iframeWin.signSave().then(function (res) {
                            if (res.code == 1) {
                                top.layer.msg(res.msg);
                                top.layer.close(index);
                                configureCom.tableReloadById(table12.id);
                            } else {
                                top.layer.alert(res.msg);
                            }
                        });
                    }
                });
            }else if(res1.code){
                layer.msg(res1.msg?res1.msg:"操作失败.");
                return;
            }else{
                layer.msg("操作失败!");
                return;
            }
        });

        //监听签名2
        $("#sign2").click(function(data){
           //TODO 后台根据模板生成pdf文件
            var res1 = null;
            var data1 = {id:cptAcceptanceId};
            $.ajax({
                url: '/api/cpt/acceptance/supervise/gcjgysjdjl2File/create?token='+token,
                type: 'post',
                cache: false,
                async:false,
                contentType : 'application/json',
                dataType : 'json',
                data :JSON.stringify(data1),
                success: function (data) {
                    res1 = data;
                    layer.closeAll('loading');
                },
                error: function (data) {
                    layer.closeAll('loading');
                    layer.msg(data.msg?data.msg:"操作失败");
                }
            });

            //查询竣工验收详情, 并判断状态, 是否显示保存按钮
            if(res1 && res1.code==0){
                sessionFun.set(configure.SESSION_SIGN_DATA,{id:cptAcceptanceId, fileName:res1.data.fileName, attId:res1.data.attId});
                //打开插件工具, 盖章上传
                top.layer.open({
                    type: 2,
                    title: '上传附件',
                    content: 'pages/completion/sign/gcjgysjdjl2Sign.html',
                    area: configureCom.Psize1,
                    cancel: function (index, layero) {
//                        configureCom.tableReloadById(table12.id);
                    },
                    btn: ['保存签章'],
                    yes: function (index, layero) {
                        var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        iframeWin.signSave().then(function (res) {
                            if (res.code == 1) {
                                top.layer.msg(res.msg);
                                top.layer.close(index);
                                configureCom.tableReloadById(table12.id);
                            } else {
                                top.layer.alert(res.msg);
                            }
                        });
                    }
                });
            }else if(res1.code){
                layer.msg(res1.msg?res1.msg:"操作失败.");
                return;
            }else{
                layer.msg("操作失败!");
                return;
            }
        });

        //待办进入, 不显示下载按钮, 根据状态显示签字按钮
        if(sessionFun.get('cptAcceptanceId')){
            //2-竣工验收监督中
            if(cptStatus && cptStatus==2){
                $("#sign1").css("display","");
                $("#sign11").css("display","");
                $("#sign2").css("display","");
            }else{
                $("#download1").css("display","");
                $("#download2").css("display","");
            }
        }else{
            //验收记录进入, 显示下载按钮, 不显示签字按钮
            $("#download1").css("display","");
            $("#download2").css("display","");
            $("#sign1").css("display","none");
            $("#sign11").css("display","none");
            $("#sign2").css("display","none");
        }

        form.render();

    });

    function getData() {
        return new Promise(function (res, rej) {
            var data = {};
            if (!window.formVerifyFun()) {
                //return false;
            }

            $('.formData').each(function (index, item) {
                var key = $(item).attr('name');
                var type = $(item).attr('type');
                if(type=='radio'){
                    data[key] = $("input[name='"+key+"']:checked").val();
                }else{
                    data[key] = $(item).val();
                }

            });
            res({result: data});
        });
    }

</script>
</body>
</html>
